package com.ttpai.boot.lbs.dao;

import com.ttpai.boot.lbs.model.MetroPointRawVO;
import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;

import java.util.List;

/**
 * `ID` int(11) NOT NULL AUTO_INCREMENT,
 * `UID` varchar(30) NOT NULL,
 * `CITY_NAME` varchar(10) NOT NULL,
 * `METRO_LINE_NAME` varchar(100) NOT NULL COMMENT '地铁线路名称',
 * `IS_PRACTICAL` int(1) NOT NULL,
 * `NAME` varchar(30) NOT NULL COMMENT '地铁站名称',
 * `Y` decimal(20,5) NOT NULL,
 * `X` decimal(20,5) NOT NULL,
 * `LNG` decimal(13,10) DEFAULT NULL,
 * `LAT` decimal(13,10) DEFAULT NULL,
 * <p>
 * Created by Kail on 2017/2/27.
 * Copyright(c) ttpai All Rights Reserved.
 */
@DAO
public interface MetroPointRawDAO {

    /**
     * 查询所有的地铁线路
     */
    @SQL("SELECT CITY_NAME,METRO_LINE_NAME,LINE_NAME,UID,IS_PRACTICAL,NAME,Y,X,LNG,LAT FROM _KAIL_METRO_POINT_RAW")
    List<MetroPointRawVO> selectAllMetroPoint();

    @SQL("SELECT CITY_NAME,METRO_LINE_NAME,LINE_NAME,UID,IS_PRACTICAL,NAME,Y,X,LNG,LAT FROM _KAIL_METRO_POINT_RAW WHERE 1=1" +
            " #if(null!=:p.cityName && ''!=:p.cityName){ AND CITY_NAME=:p.cityName}" +
            " #if(null!=:p.lineName && ''!=:p.lineName){ AND LINE_NAME=:p.lineName}" +
            " ORDER BY ID")
    List<MetroPointRawVO> selectAllMetroPoint(@SQLParam("p") MetroPointRawVO p);

    @SQL("SELECT CITY_NAME,METRO_LINE_NAME,LINE_NAME,UID,IS_PRACTICAL,NAME,Y,X,LNG,LAT FROM _KAIL_METRO_POINT_RAW WHERE UID=:uid")
    List<MetroPointRawVO> selectMetroPointById(@SQLParam("uid") String uid);

    @SQL("INSERT INTO _KAIL_METRO_POINT_RAW (CITY_NAME,METRO_LINE_NAME,LINE_NAME,UID,IS_PRACTICAL,NAME,Y,X,LNG,LAT) VALUES (:mp.cityName,:mp.metroLineName,:mp.lineName,:mp.uid,:mp.isPractical,:mp.name,:mp.y,:mp.x,:mp.lng,:mp.lat)")
    Integer insertMetroPoint(@SQLParam("mp") MetroPointRawVO metroPoint);

    @SQL("UPDATE _KAIL_METRO_POINT_RAW SET " +
            " #if(null != :mp.lng){ LNG=:mp.lng, } " +
            " #if(null != :mp.lat){ LAT=:mp.lat, } " +
            " ID=ID " +
            " WHERE UID=:mp.uid")
    Integer updateMetroPoint(@SQLParam("mp") MetroPointRawVO metroPoint);


}
